package com.cskaoyan.wordmemorize.controller.admin;

import ch.qos.logback.classic.util.LevelToSyslogSeverity;
import com.cskaoyan.wordmemorize.annotation.OperateLog;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteLevelOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.LevelDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.LevelCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.service.LevelService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "等级-特权管理-等级管理")
@RestController
@RequestMapping("/admin/level")
public class LevelController {
    @Resource
    LevelService levelService;

    // 分页查询等级(后台等级权限管理-等级管理)
    @GetMapping("/list")

    public Result<PageDTO<LevelDTO>> getLevelList(PageRequest pageRequest) {
        PageDTO<LevelDTO> levelList = levelService.getLevelList(pageRequest);
        return Result.ok(levelList);
    }

    // 添加等级(后台等级权限管理-等级管理)
    @PostMapping()
    @OperateLog(dateType = "等级管理", operateType = 1)
    public Result<String> addLevel(@RequestBody LevelCommand command) {
        levelService.addLevel(command);
        return Result.ok();
    }

    // 修改等级(后台等级权限管理-等级管理)
    @PutMapping()
    @OperateLog(dateType = "等级管理", operateType = 2)
    public Result<String> updateLevel(@RequestBody LevelCommand command) {
        levelService.updateLevel(command);
        return Result.ok();
    }

    // 删除等级(后台等级权限管理-等级管理)
    @DeleteMapping("/{id}")
    @OperateLog(dateType = "等级管理", operateType = 3)
    public Result<DeleteLevelOperateDTO> deleteLevel(@PathVariable Long id) {
        DeleteLevelOperateDTO deleteLevelOperateDTO = levelService.deleteLevel(id);
        return Result.ok(deleteLevelOperateDTO);
    }

    // 批量删除等级(后台等级权限管理-等级管理)
    @DeleteMapping("/batch")
    @OperateLog(dateType = "等级管理", operateType = 4)
    public Result<List<DeleteLevelOperateDTO>> deleteLevels(@RequestBody BatchDeleteCommand command) {
        List<DeleteLevelOperateDTO> deleteLevelOperateDTOS = levelService.deleteLevels(command);
        return Result.ok(deleteLevelOperateDTOS);
    }
}
